package cn.jn.lhm.netty.part04;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author lhm 2753914576@qq.com
 * @time 2023/7/12 - 22:35
 **/
@Slf4j
public class TestJdkFuture {
    @SuppressWarnings("all")
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);

        Future<String> result = executorService.submit(() -> {
            try {
                Thread.sleep(2000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            log.info("返回结果.....");
            return "aaa";
        });

        // 同步等等结果
        log.info("获取的结果是:{}", result.get());
        executorService.shutdown();
    }
}
